package com.hui.modules.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hui.modules.sys.model.User;
import com.hui.modules.sys.service.UserService;
import com.hui.utils.Ret;
import com.hui.utils.MD5;

@Controller
public class LoginController {

	@Autowired
	private UserService userService;
	
	
	@RequestMapping("/login")
	@ResponseBody
	public Ret login(User user){
		String name = user.getUsername();
		String pwd = MD5.getMD5(user.getPassword());
		
	
		System.out.println("user:"+name+"-"+pwd);
//		if(name != null && pwd != ""){
//			if(name.equals("admin")&& pwd.equals("123")){
//				
//				System.out.println("code="+Ret.ok().get("code"));
//				return Ret.ok();
//			}
//		}
		User users = userService.queryUser(user);
		if(pwd.equals(users.getPassword())){
			System.out.println("code="+Ret.ok().get("code"));
			return Ret.ok();
		}
		
		return Ret.error();
	}
}
